<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
         <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
        <meta http-equiv="Pragma" content="no-cache" />
        <meta http-equiv="Expires" content="0" />    
    <title>栏目列表</title>
</head>
<body>
   
    <div class="container-fluid">
        <div class="line20"></div>    
        <a class="btn btn-primary" href="/cms/node/add">新增栏目</a> &nbsp; &nbsp;
         <a class="btn btn-warning"  id="taxis">保存排序</a>
        <div class="line10"></div>
          
        <table class="table table-striped table-hover" border="0" cellpadding="0" cellspacing="0"  id="userTable">
            <thead>
                <tr>
                    <th width="40">ID</th>
                    <th width="200">栏目名称</th>
                    <th width="100">引用</th>
                    <th width="120">排序</th>
                    <th width="100">访问路径</th> 
                     <th width="100">启用</th> 
                    <th width="200">操作</th>                            
                </tr>
            </thead>
            <tbody>
                <td colspan="9">数据加载中……</td>
            </tbody>
        </table>    
    </div>
   
<link rel="stylesheet" type="text/css" href="/admin/res/style.css">
<link rel="stylesheet" type="text/css" href="/admin/res/index.css">
<script src="/admin/res/jquery.min.js"></script>
<script src="/skin/scripts/bs.min.js"></script>
<script src="/admin/res/cookie.js"></script>
<script src="/admin/res/layindex.js"></script>
    <script type="text/javascript">    
      
   
        $(document).ready(function () {

            var totalpages, totalrecords, pageindex, pagesize, startindex
            ajaxData = {};
            //加载详细列表
            queryUserInfo = function (pageIndex) {              
                ajaxData.pageindex = 1;
                ajaxData.pagesize = 10;
                if (pageIndex && /^\d*$/.test(pageIndex) && pageIndex > 0) {
                    ajaxData.pageindex = pageIndex;
                }
                $.ajax({
                    url: '/cms/node/jsonlist',
                    type: 'post',
                    dataType: 'json',
                    data:ajaxData
                })
                .done(function (data) {
                	 if (data.length == 0) {  
                		 $('#userTable tbody').html('<tr><td colspan=8>无数据</td></tr>');
                		 return;                        
                     }
                    var index, tb = $('<tbody></tbody>');
                    totalpages = data.totalpages * 1;
                    totalrecords = data.totalrecords * 1;
                    pageindex = data.pageindex * 1;
                    pagesize = data.pagesize * 1;
                    startindex = (pageindex - 1) * pagesize + 1;
                    for (var i = 0; i < data.length; i++) {
                        index = startindex + i;
                        tb.append($('<tr></tr>')
                              .append('<td>' + data[i].id + '</td>')
                              .append('<td style="text-align:left">'+spliteline(data[i].layer)+'<span class="folder-open"></span>' + data[i].title + '</td>')  
                              .append('<td>' + data[i].call + '</td>')
                              .append('<td><input type="number" class=taxis style="border:1px solid #ddd;width:30px;text-align:center;" value="' + data[i].taxis + '" id="' + data[i].id + '" /></td>')
                              .append('<td>' + data[i].path + '</td>')   
                              .append('<td><a href="/cms/node/islock/'+data[i].id+'">' + (data[i].deleted?"是":"<font class=cr>否</font>") + '</a></td>')                         
                              .append($('<td></td>')
                                         .append($('<a href="/cms/node/add/'+data[i].id+'" >修改</a>')
                                            .data('content', data[i])
                                        )
                                         .append($('<a id="del">&nbsp;&nbsp; 删除</a>')
                                            .data('content', data[i])
                                        ))                            
                          );
                    }
                    $('#userTable tbody').replaceWith(tb);
                    $('#jump').val(pageindex);
                    $('.u-pager-info').html('共' + totalrecords + '条记录，每页' + pagesize + '条，共' + totalpages + '页，现在是第' + pageindex + '页');

                });
            };
            queryUserInfo();
          
function spliteline(layer)
{
	var str='';	
	str+='<span style="display:inline-block;width:'+24*layer+'px;"></span>';
	return str+'<span class="folder-line"></span>';
}

           $('#taxis').click(function(){
        	   var map = new Array(); 
        	   $('.taxis').each(function(i){
        		   var id = $(this).attr("id");
        		   var value=$(this).val();
        		   map.push({id,value});
        	   }) 
        	   var data=JSON.stringify(map)
        	   console.log(data); 
        	   console.log(map); 
        	   
        	   $.ajax({
        	        url: '/cms/node/taxis',
        	        type: 'post',
        	        dataType: 'json',
        	        contentType: "application/json",
        	        data:data
        	    })
        	     .done(function (data) {
        	        alert('ok')
        	      });
        	   
        	   /*
        	   ajaxurl('/cms/node/taxis', 'post', data, function success(data) {
                   if (data.status == 1) {                            
                     //  queryUserInfo();
                	   alert(data.status);
                   }
                   else
                       alert(data.msg);
               });   
        	  */
           })
           
            //提示删除
             $("#userTable").on("click", "#del", {}, function (event) {
                 var content = $(this).data('content');
                 if (window.confirm('确定删除 ' + content.title + ' ？')) {
                     ajaxurl('/cms/node/jsondel/'+content.id, 'post', {_method:'delete'}, function success(data) {
                         if (data.status == 1) {                            
                             queryUserInfo();
                         }
                         else
                             alert(data.msg);
                     });

                 }
                

             });
           
        });
      
    </script>
</body>
</html>
